# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=zziplib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.13.62
pkgrel=4
pkgdesc="A lightweight library that offers the ability to easily extract data from files archived in a single zip file (mingw-w64)"
arch=('any')
url="http://zziplib.sourceforge.net"
license=("LGPL, MPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-SDL"
             "python2")
depends=( "${MINGW_PACKAGE_PREFIX}-zlib")
optdepends=("${MINGW_PACKAGE_PREFIX}-SDL: SDL_rwops for ZZipLib")
options=('staticlibs' 'strip')
source=("https://downloads.sourceforge.net/zziplib/${_realname}-${pkgver}.tar.bz2"
    "configure.patch"
    "mingw-mmap-workaround.patch")
sha256sums=('a1b8033f1a1fd6385f4820b01ee32d8eca818409235d22caf5119e0078c7525b'
            '3ba2ef5b7330437f0662726358b8d5d8cb39c521115eead69cd3b42be5e1e889'
            'c727f337eba65fb8cff95680c08daa6a74aafa6bd73b2fe945885f86dc265583')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i $srcdir/configure.patch
  patch -Np1 -i $srcdir/mingw-mmap-workaround.patch
}

build() {
  export PYTHON=/usr/bin/python2
  export PERL=/usr/bin/perl
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-zlib=${MINGW_PREFIX} \
    --enable-sdl

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
